package gnacos

import (
	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
	"github.com/nacos-group/nacos-sdk-go/vo"
)

type RegisterService struct {
	iClient naming_client.INamingClient
}

func GenerateRegisterService(namespace string, addrs []Addr, options ...OptFunc) (*RegisterService, error) {
	initConfig(namespace, addrs, options...)
	client, err := clients.NewNamingClient(vo.NacosClientParam{
		ClientConfig:  clientConfig,
		ServerConfigs: serverConfigs,
	})
	if err != nil {
		return nil, err
	}
	return &RegisterService{
		client,
	}, nil
}

func (registerService RegisterService) Register(param vo.RegisterInstanceParam) (bool, error) {
	return registerService.iClient.RegisterInstance(param)
}

func (registerService RegisterService) Deregister(param vo.DeregisterInstanceParam) (bool, error) {
	return registerService.iClient.DeregisterInstance(param)
}
